package drive.Controller;

import drive.Model.Image;
import drive.Service.ServiceInterface.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/image")
public class ImageController {

    @Autowired
    private ImageService imageService;

    @GetMapping()
    public String getAllImages() {
        return imageService.findAll();
    }

    @GetMapping("/{imageID}")
    public String getImageByImageID(@PathVariable("imageID") Integer imageID) {
        return imageService.findByImageID(imageID);
    }

    @GetMapping("/article/{articleID}")
    public String getImagesByArticleID(@PathVariable("articleID") Integer articleID) {
        return imageService.findByArticleID(articleID);
    }

    @PostMapping()
    public String addImage(@RequestBody Image image) {
        return imageService.add(image);
    }

    @PutMapping()
    public String updateImage(@RequestBody Image image) {
        return imageService.update(image);
    }

    @DeleteMapping("/{imageID}")
    public String deleteImage(@PathVariable("imageID") Integer imageID) {
        return imageService.delete(imageID);
    }
}